package com.chai.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.chai.service.BookService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
/**
 * jdbc的配置类
 * 第三方bean的管理，bean的id就是方法名称
 * */
import javax.sql.DataSource;

public class JdbcConfig {
    //第三方bean的简单类型的注入
    @Value("${jdbc.driver}")
    private String driver;
    @Value("{jdbc.url}")
    private String url;
    @Value("{jdbc.username}")
    private String username;
    @Value("{jdbc.password}")
    private String password;
    @Bean

    //引用类型的注入：直接在方法中添加变量(成员变量)，进行自动装配
    public DataSource dataSource(BookService bookService){
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName(driver);
        druidDataSource.setUrl(url);
        druidDataSource.setUsername(username);
        druidDataSource.setPassword(password);
        return druidDataSource;
    }
}
